import java.io.BufferedReader;
import java.util.Scanner;


public class HEWWIW {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Building b = new Building(19, "b");
		JailCell mIT=new JailCell(5, "jail", 12398);
		int win;
		int bribe = 0 ;
		int firstTime = 20;
		int avoid = 0;
		int money =0;
		item string = new item("A small STRING dangling from the ceiling. It seems to be connected to a lightbulb.", "You hit the STRING. It swings back towards you.", "You rip the STRING of the bulb turning the light off forever.");
		item bucket = new item("Strange. There appears to be a loose BOARD on the bucket, and some REDPOWDER is spilling out the gap.", "You kick the bucket.", "The BUCKET is stuck to the floor.");
		item cot = new item("It's a COT. You can sleep on it if you don't mind the stains.", "You lie on top of the cot and feel yourself drift into sleep.", "The cot is far to large to lift.");
		item board = new item("Well, it's really more of a stick than a BOARD. Get 2 stone and you could make a sword!", "I... don't really think this is something you can use right now.", "You pry the board off the bucket.");
		item cellDoor = new item("It is a DOOR. An iron DOOR. Also, it's closed. And you can't walk through it while it's closed.", "The door is locked. You do not have a key.", "Are you serious? Taking a DOOR? What is your problem?");
		item redstone = new item("It appears to be  a powdery REDSTONE.", "You hit the dust and it glows.", "You scoop up some of the stuff into your pockets. Will it wash off?");
		item torch = new item("A crude redstone TORCH.", "You place the TORCH on the ground and the DOOR swings open.", "You can't take something you are holding.");
		item poster = new item("A large poster of an athlete or something hanging on the wall.", "You look behind it and you see a little camera inside the wall.", "You fold up the poster neatly and put it in you pocket.");
		System.out.println("You are locked in a room. A jail cell room. What is your prison name?");
		int camera=1;
		Scanner scan= new Scanner(System.in);
		Game l = new Game(); 
		if (scan.equals("Shoop Da Whoop"))
		{
			 l.setfiringMalazor(1);
		}
		else
		{
			l.setfiringMalazor(0);
		}
		String nameIn = scan.nextLine();
		mIT.setName(nameIn);
		System.out.println("What crime did you commit to get in? Mugging(1), Tax Evasion(2), Robbery(3), Assasination(4), or Breaking Out Of Jail (5), or are  you innocent(0)?");
		Scanner scan1 = new Scanner(System.in);
		int s = scan.nextInt();
		mIT.setCrime(s);
		int freedom=0;
		while (s==0)
		{
			freedom=freedom+5;
			System.out.println("No, really. What crime did you commit.");
			if(freedom==50)
			{
				System.out.println("Convinced of your innocence, the guards let you go.");
				return;
			}
			s = scan.nextInt();
		}
		if (s==5)
		{
			System.out.println("You are placed in a maximum security prison due to your history, and you cannot escape with your limited knowledge.");
		return;
		}
		if (s!=1&&s!=2&&s!=3&&s!=4&&s!=5&&s!=0)
		{
			System.out.println("OK.... That's the death penalty. *BANG!*");
			return;
		}	
		if (s==4||s==1||s==2||s==3)
		{
			/*System.out.println("Looking around your cell you see darkness. You fumble and find a STRING.");
			boolean lightbulbY= false;
			System.out.println("You can LOOK'OBJECT' to see object, TAKE'OBJECT' to obtain items, USE'OBJECT' to use items, and USE'OBJECT''OBJECT' to use an item on an item. (Ex: USEBRICKWINDOW). ");
			Scanner scanLight = new Scanner(System.in);
			boolean lightOn=false;
			while(lightOn==false)
			{
				String lighT = scanLight.next();
				if (lighT.equals("LOOKSTRING"))
				{
				System.out.println(string.getLOOK());
				string.setUSE("You pull the STRING and the light turns on.");
				lightbulbY=true;
				}
				else if (lighT.equals("USESTRING"))
				{
				System.out.println(string.getUSE());
					if (lightbulbY==false){
						System.out.println("Um. Maybe if you knew more about this STRING you could use it.");
					}
					else{
						lightOn=true;
					}
				}
				else if(lighT.equals("TAKESTRING"))
				{
				System.out.println(string.getTAKE());
				return;
				}
				else
				{
					System.out.println("I'm sorry, I don't think you know what you're doing. Try again");
				}
			}
			System.out.println("The room is a small cube with walls made of bedrock. One wooden BUCKET sits in a corner. A POSTER hangs on the wall. There is a folding COT in the other corner. An iron DOOR is set into the wall. It is locked.");
			System.out.println("You may LOOKROOM at any time to be reminded of what is in it.");
			boolean doorOpen=false;
			boolean torchMade=false;
			boolean redstoneFound=false;
			boolean boardOrStick=false;
			boolean slept=false;
			int posteR=0;
			Scanner scanCell = new Scanner(System.in);
			while(doorOpen==false)
			{
				String room = scanCell.next();
				if (room.equals("LOOKROOM"))
				{
					System.out.println("The room is a small cube with walls made of bedrock. One wooden BUCKET sits in a corner. A poster hangs on the wall. There is a folding COT in the other. An iron DOOR is set into the wall. It is locked.");
				}
				else if(room.equals("USETORCH")||room.equals("USETORCHDOOR"))
				{
					if(torchMade==true){
						System.out.println(torch.getUSE());
						doorOpen=true;
					}
					else
					{
						System.out.println("What torch?");
					}
				}
				else if (redstoneFound==true)
				{
					if (boardOrStick==true)
					{
						if (room.equals("USEBOARDREDSTONE")||room.equals("USEREDSTONEBOARD"))
						{
							System.out.println("You spit onto the board then dip it into the powder so it sticks. You just made a redstone TORCH!");
							torchMade=true;
						}}
					else
					{
						System.out.println("Hey that board looks really interesting.");
					}
				}
				
				else if(room.equals("LOOKBUCKET"))
				{
				System.out.println(bucket.getLOOK());
				}
				else if(room.equals("LOOKPOSTER"))
				{
					if(camera==0)
					{
						poster.setLOOK("There is the poster preventing the camera from watching you.");
					}
					if(camera==2)
					{
						poster.setLOOK("A large poster of an athlete or something hanging on the wall.");
					}
					if(camera==3)
					{
						System.out.println("There's a camera behind there, I wouldn't take it if i was you.");
					}
						
				System.out.println(poster.getLOOK());
				}
				else if(room.equals("LOOKREDPOWDER"))
				{
				System.out.println(redstone.getLOOK());
				redstoneFound=true;
				}
				if (redstoneFound==true)
				{
					if(room.equals("LOOKREDSTONE"))
					{
				System.out.println(redstone.getLOOK());
				}}
				if (torchMade==true)
				{
				if(room.equals("LOOKTORCH"))
				{
				System.out.println(torch.getLOOK());
				}}
				else if(room.equals("LOOKCOT"))
				{
				System.out.println(cot.getLOOK());
				}
				else if(room.equals("LOOKDOOR"))
				{
				System.out.println(cellDoor.getLOOK());
				}
				else if(room.equals("LOOKBOARD"))	
				{
				System.out.println(board.getLOOK());
				boardOrStick=true;
				}
				else if(room.equals("USEDOOR"))
				{
				System.out.println(cellDoor.getUSE());
				}
				else if(room.equals("USEPOSTER"))
				{
				System.out.println(poster.getUSE());
				camera=3;
					if(camera==2){
						System.out.println("You place the poster back over the camera.");
						camera=0;
						posteR=posteR++;
					}
				}
				else if(room.equals("USEBUCKET"))
				{
				System.out.println(bucket.getUSE());
				}
				else if(room.equals("USECOT"))
				{
				System.out.println(cot.getUSE());
				doorOpen=true;
				slept=true;
				System.out.println("You now walk free as the door automatically unlocks. But because the gaurds never saw you they might not know you have served your time.");
				}
				else if(room.equals("USEBOARD"))
				{
				System.out.println(board.getUSE());
				}
				else if(room.equals("TAKEBUCKET"))
				{
				System.out.println(bucket.getTAKE());
				}
				else if(room.equals("TAKECOT"))
				{
				System.out.println(cot.getTAKE());
				}
				else if(room.equals("TAKEPOSTER"))
				{
					if(posteR==0)
					{
					posteR=posteR++;
				System.out.println(poster.getTAKE());
					if(camera==3)
					{
						System.out.println("Now you're being watched.");
					}
					camera=2;
					}
					else
					{
						System.out.println("The poster is in your pocket, you have it.");
					}
					}
				else if(room.equals("TAKEDOOR"))
				{
				System.out.println(cellDoor.getTAKE());
				}
				else if(room.equals("TAKEBOARD"))
				{
				System.out.println(board.getTAKE());
				}
				else if (redstoneFound==true)
				{
					if(room.equals("TAKEREDSTONE"))
					{
						System.out.println(redstone.getTAKE());
				}}
				else if (torchMade==true)
				{
					if(room.equals("TAKETORCH"))
					{
						System.out.println(torch.getTAKE());
				}}
				else
				{
					System.out.println("I have no idea what your trying to do, but you can't do it. Try LOOKing around.");
				}*/
		//	}	
		}
		if(camera==2)
		{
			firstTime = firstTime - 5;
			System.out.println("You better move fast, the guards probably saw your escape with that camera....");
		}
		else{
			System.out.println("You got out da cell! But now a wild guard appears...");
		}
		if (s==1){
    		money = 30000;
            System.out.println("How much money do you want to try to bribe the guards with to let you out? You have $30,000 on you and nothing in the bank.");
            Scanner scanT1 = new Scanner(System.in);
            bribe = scanT1.nextInt(); // this function inputs a bribe to bribe the guard
    	}
    	if (s==2){
    		money = 1000000;
            System.out.println("How much money do you want to try to bribe the guards with to let you out? You have $200,000 on you and $800,000 in the bank.");
            Scanner scanT1 = new Scanner(System.in);
            bribe = scanT1.nextInt(); // this function inputs a bribe to bribe the guard
    	}
    	if (s==3){
    		money= 925000;
            System.out.println("How much money do you want to try to bribe the guards with to let you out? You have $50,000 on you and $875,000 in the 'bank'.");
            Scanner scanT1 = new Scanner(System.in);
            bribe = scanT1.nextInt(); // this function inputs a bribe to bribe the guard
    	}
    	if (s==4){
    		money = 100000;
            System.out.println("How much money do you want to try to bribe the guards with to let you out? You have $100,000 on you and nothing in the bank.");
            Scanner scanT1 = new Scanner(System.in);
            bribe = scanT1.nextInt(); // this function inputs a bribe to bribe the guard
    	}
            
            if (bribe==900000)
            {
                System.out.println("You escaped jail through bribery!");//if the user bribes the guard 99999 $ they instantly win
                return;
            }
            if (bribe<900000) 
            {
            	System.out.println("The guards accept the bribe then engages you in combat."); // if the user doesn't bribe the guard enough the guard takes the money and attacks the user
                Game g = new Game();
                win = g.game(s); // this function calls the game.java class
                // it returns win which tells the game if the user won or lost the combat
                g.setMoney(-bribe); // this fuction is also in the game.java file and subtracts the bribe from the users money
                if (win == 0){ // this means if the user lost the combat that the game is over
                
                	System.exit(0);
                	
                }
                else{
                	
               	 System.out.println("You have defeated the guard what would you like to do now?");
               	 System.out.println("A: Take the gun from the guard");
               	 System.out.println("B: Take back you bribe");
               	 System.out.println("C: Put on the police officer's suit");
               	 System.out.println("D: Hid in the corner.");
               	 Scanner scan1v = new Scanner(System.in);
                    String victory = scan1v.next(); // this is a mutiple choice question regarding the charaters action after defeting the guard
                    if (victory.substring(0,1).equals ("a") || victory.substring(0,1).equals ("A")){ //option a 
                   	 System.out.println("You now have a gun");
                   	 g.setGun(1);
                    }
                    if (victory.substring(0,1).equals ("b")|| victory.substring(0,1).equals ("B")){//option b
                   	 System.out.println("Your money has been restored");
                   	 g.setMoney(bribe);
                    }
                    if (victory.substring(0,1).equals ("c") || victory.substring(0,1).equals ("c")){//option c
                   	 System.out.println("Your chance to avoid combat increased 10");
                   	 g.setAvoid(10);
                    }
                    if (victory.substring(0,1).equals ("d")|| victory.substring(0,1).equals ("D")){//option d
                   	 System.out.println("You are locked back in jail and die a slow painful death");
                   	 System.exit(0);
                    }
                    System.out.println("You have defeted the guard, what will you do now?"); // this is the  next multiple choice question in the story
                    System.out.println("A: Search the room");// this activates a separate code that 
                  	System.out.println("B: Continue on");
                  	Scanner scan1c = new Scanner(System.in);
                    String path = scan1v.next();
                    if (path.substring(0,1).equals ("a")|| path.substring(0,1).equals ("A")){
                    	while (firstTime>0){
                    		 System.out.println("You look around the office of the office of late guard and see three things of interest");
                        	 System.out.println("A: Examine the safe");
                        	 System.out.println("B: Examine the computer");
                        	 System.out.println("C: Examine the file cabinet");
                        	 System.out.println("D: Leave the room");
                        	 Scanner office = new Scanner(System.in);
                             String examine = office.next();
                        if (examine.substring(0,1).equals ("a") || examine.substring(0,1).equals ("A")){
                    	g.firstRoom(s);         
                    	g.getfirstTime();
                        }
                    	else if (examine.substring(0,1).equals ("b")|| examine.substring(0,1).equals ("B")){
                    	g.secondRoom(s);
                     	g.getfirstTime();
                    	}
                    	else if (examine.substring(0,1).equals ("c")|| examine.substring(0,1).equals ("C")){
                    	g.thirdRoom(s);
                        g.getfirstTime();
                    	}
                    	else if (examine.substring(0,1).equals ("d")|| examine.substring(0,1).equals ("D")){
                    		firstTime=-1;
                    	}
                    	if (firstTime==0){
                    		System.out.println("You are out of time you must move on.");
                        	break;
                    	}
                    }
                    System.out.println("You move out of the brightly lit office and into the dark coridors of the police station");
                    System.out.println("Do you take a left or a right?");
                    Scanner firstCor = new Scanner(System.in);
                    String cor1 = firstCor.next();
                    if (cor1.equals ("left") || cor1.equals("Left")){
                    	 g.setRandAvoid();
                		 avoid = g.getAvoid();
                		 g.zeroAvoid();
                    	if (avoid>=100){
                            System.out.println("There was a guard but, you managed to avoid it");

                    	}
                    	else{
                    		 System.out.println("As you turn the corrner you run straight into a guard. He engages combat");
                    		g.setEnemyHealth(1);
                            g.setEnemy(1);
                    		 win = g.game(s);
                    		if (win == 0){
                    		System.exit(0);
                    		}
                    		
                    	}
                    	avoid = 0;
                    	System.out.println("You procced into the station until you come upon a corner do you take a left or right?");
                    	Scanner secondCor = new Scanner(System.in);
                        String cor2 = secondCor.next();
                        if (cor2.equals ("left") || cor2.equals("Left")){
                        	System.out.println("As you are walking you suddenly fall through a manhole cover into the sewers");
                        	System.out.println("You are attacked by a six-legged aligator");
                        	g.setEnemyHealth(3);
                        	g.setEnemy(3);
                        	win =  g.game(s);
                   		 g.getfirstTime();
                   		 if (win ==0){
                   			 System.exit(0);
                   		 }
                   		 System.out.println("You have beaten the Aligator and escape through the sewer.");
                   		g.end();
                        	
                        	
                        }
                        if (cor2.equals ("right") || cor2.equals("Right")){
                        	System.out.println("You come put of the hallway into the armory and see the Quartermaster, he engages you in combat.");
                        	g.setEnemyHealth(3);
                        	g.setEnemy(3);
                        	win =  g.game(s);
                   		 g.getfirstTime();
                   		 if (win ==0){
                   			 System.exit(0);
                   		 }
                   		 System.out.println("You have beaten the Quartermaster and use a rocket launcher to blow up the wall.");
                   		g.end();
                        }
                        
                    }
                    if (cor1.equals ("right") || cor1.equals("Right")){
                    	 System.out.println("You emerge into a locker room but, you have no time to explore do you go straight or right");
                    	 Scanner thirdCor = new Scanner(System.in);
                         String cor3 = thirdCor.next();
                    	 if (cor3.equals ("right") || cor3.equals("Right")){
                    		 System.out.println("You emerge into the Police chief's office and are engaged in battle ") ;
                    		 g.setEnemyHealth(2);
                    		 g.setEnemy(2);
                    		 win =  g.game(s);
                    		 g.getfirstTime();
                    		 if (win ==0){
                    			 System.exit(0);
                    		 }
                    		 System.out.println("You have beaten the Police chief and escape out the back door");
                    		 g.end();
                    	 }
                    	 if   (cor3.equals ("straight") || cor3.equals("Straight")){
                    		 System.out.print("As your walking you run into a guard");
                    		 g.setRandAvoid();
                    		 avoid = g.getAvoid();
                    		 g.zeroAvoid();
                    		 if (avoid > 100){
                    			 System.out.println(" and he ingages you in combat");
                    			 
                    			   	g.setEnemyHealth(1);
                                	g.setEnemy(1);
                    			 win= g.game(s);
                    			 if (win==0){
                    				 System.exit(0);
                    			 }
                    		
                    		 	 		
                    		 }
                    		 else {
                    			 System.out.println(" but you avoid combat.");
                    		 }
                    		 avoid = 0;
                    		 System.out.println(" Finally you emerge into the main lobby, however it is guarded by the second in comand");
                    		 g.setEnemy(3);
                    		   	g.setEnemyHealth(3);
                            	
                			 win= g.game(s);
                			 if (win==0){
                				 System.exit(0);
                			 }
                			 System.out.println("Congratulations, you walk out of the front door of the jail");
                			 g.end();
                    	 }
                    }
                    	}
                    	
                }
                    
                 
                    
                    	
                   }
            
            
            if (bribe>money)
            {
                    System.out.println("IMPOSIBLE. Start over.");
                    return;
            }
     
     

     
            
    //System.out.println("H");
    mIT.setCrime(s);
    mIT.getCrime();
}               
}